<?php

/**
 * This is the model class for table "static_lookup".
 *
 * The followings are the available columns in table 'static_lookup':
 * @property string $lu_id
 * @property string $lu_name
 * @property string $lu_val
 * @property string $default_val
 * @property string $data_type
 * @property string $client_id
 */
class StaticLookup extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return StaticLookup the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'static_lookup';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('lu_name, lu_val', 'required'),
			array('lu_name, lu_val, default_val', 'length', 'max'=>200),
			array('data_type', 'length', 'max'=>45),
			array('client_id', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('lu_id, lu_name, lu_val, default_val, data_type, client_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'lu_id' => 'Lookup',
			'lu_name' => 'Lookup Name',
			'lu_val' => 'Lookup Val',
			'default_val' => 'Default Val',
			'data_type' => 'Data Type',
			'client_id' => 'Client',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('lu_id',$this->lu_id,true);
		$criteria->compare('lu_name',$this->lu_name,true);
		$criteria->compare('lu_val',$this->lu_val,true);
		$criteria->compare('default_val',$this->default_val,true);
		$criteria->compare('data_type',$this->data_type,true);
		$criteria->compare('client_id',$this->client_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	/**
	 * Returns the data model based on the name given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param string $luname the name of the model to be loaded
	 * @return StaticLookup the loaded model
	 * @throws CHttpException
	 */
	public function loadLookup($luname)
	{
		$request = array(':lu_name' => $luname);
		$modelArr = StaticLookup::model()->findAll("lu_name=:lu_name", $request);
		if($modelArr===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $modelArr;
	}
	
// 	public function getListForDropdown($models, $text, $value){
// 		$list = array();
// 		$model = new StaticLookup;
// 		foreach ($models as $model){
// 			$listItem = array($model->lu_val => $model->default_val);
// 			array_push($list, $listItem);
// 			$listItem = null;
// 		}
// 		return $list;
// 	}
}